package com.fearless.demo03;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Date;

public class MyInvocationHandler implements InvocationHandler {

    private Object target;

    public MyInvocationHandler(Object target) {
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        //功能增强
        System.out.println(new Date());
        System.out.println("功能增强");


        //通过代理对象执行方法时，会调用这个invoke

        //执行目标类的方法，通过method实现。
         Object result= method.invoke(target,args);


        return result;
    }


}
